<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="title">
            <h:outputText value="Create Sales Inquiry"></h:outputText>
        </ui:define>
        <ui:define name="content">
            <h:form rendered="#{loginBacking.addSalesInquiry}">
                <p:panel header="Create Sales Inquiry">
                    <p:messages globalOnly="true"/>
                    <br />
                    <h:panelGrid columns="4">
                        <h:outputLabel value="#{bundle.CreateSalesInquiryEntityLabel_salesLead}" for="salesLead" rendered="#{salesInquiryEntityController.displaySalesLeadTab()==true}"/>
                        <p:inputText id="salesLead" binding="#{salesLead}" value="#{salesInquiryEntityController.selected.salesLead}" rendered="#{salesInquiryEntityController.displaySalesLeadTab()==true}" />
                        <p:commandButton ajax="false" value="Browse" rendered="#{salesInquiryEntityController.displaySalesLeadTab()==true}" action="#{salesLeadEntityController.recreateModel()}" onclick="salesLead.show();" type="button" immediate="true"/>


                        <h:outputLabel value="#{bundle.CreateSalesInquiryEntityLabel_salesLead}" for="salesLead" rendered="#{salesInquiryEntityController.displaySalesLeadTab()==false}"/>
                        <p:inputText id="salesLead1" disabled="true" rendered="#{salesInquiryEntityController.displaySalesLeadTab()==false}" />
                        <p:commandButton value="Browse" disabled="true" rendered="#{salesInquiryEntityController.displaySalesLeadTab()==false}" />
                        <h:message styleClass="errorMsg" for= "salesLead" />

                        <h:outputLabel value="#{bundle.CreateSalesInquiryEntityLabel_customer}" for="customer" rendered="#{salesInquiryEntityController.displayCustomerTab()==true}"/>
                        <p:inputText id="customer" value="#{salesInquiryEntityController.selected.customer}" rendered="#{salesInquiryEntityController.displayCustomerTab()==true}">
                            <f:validator validatorId="macTeam.SalesLeadCustomerSelectOneValidator"/>
                            <f:attribute name="salesLead" value="#{salesLead.value}" />
                        </p:inputText>
                        <p:commandButton ajax="false" value="Browse" rendered="#{salesInquiryEntityController.displayCustomerTab()==true}" action="#{customerEntityController.recreateModel()}" onclick="customer.show();" type="button" immediate="true"/>


                        <h:outputLabel value="#{bundle.CreateSalesInquiryEntityLabel_customer}" for="customer" rendered="#{salesInquiryEntityController.displayCustomerTab()==false}"/>
                        <p:inputText id="customer1" disabled="true" rendered="#{salesInquiryEntityController.displayCustomerTab()==false}"/>
                        <p:commandButton value="Browse" disabled="true" rendered="#{salesInquiryEntityController.displayCustomerTab()==false}"/>
                        <h:message styleClass="errorMsg" for= "customer" />
                    </h:panelGrid> 
                    <br />
                    <p:separator />
                    <br />
                    <h:panelGrid columns="3">
                        <h:outputLabel value="Product:" style="font-weight:bold"/>
                        <h:outputLabel value="Quantity (Number of Case(s)):" style="font-weight:bold"/>
                        <h:outputLabel value =""/>
                        <h:outputLabel value="Classic Nutri Bar (Nuts)" for="product" />
                        <p:inputText id="quantity" binding="#{quantity1}" value="#{salesInquiryEntityController.selectedPQP.quantity}" title="#{bundle.CreateProductQuantityPriceEntityTitle_quantity}" />
                        <h:outputLabel value =""/>

                        <h:outputLabel value="Classic Nutri Bar (Fruits)" for="product" />
                        <p:inputText id="quantity2" binding="#{quantity2}" value="#{salesInquiryEntityController.selectedPQP2.quantity}" title="#{bundle.CreateProductQuantityPriceEntityTitle_quantity}" />
                        <h:outputLabel value =""/>

                        <h:outputLabel value="Premium Power Bar (Chocolate Nuts)" for="product" />
                        <p:inputText id="quantity3" binding="#{quantity3}" value="#{salesInquiryEntityController.selectedPQP3.quantity}" title="#{bundle.CreateProductQuantityPriceEntityTitle_quantity}" />
                        <h:outputLabel value =""/>

                        <h:outputLabel value="Premium Power Bar (Redcurrant Fruits)" for="product" />
                        <p:inputText id="quantity4"  value="#{salesInquiryEntityController.selectedPQP4.quantity}" title="#{bundle.CreateProductQuantityPriceEntityTitle_quantity}" >
                            <f:validator validatorId="macTeam.ProductQuantityInputValidator"/>
                            <f:attribute name="quantity1" value="#{quantity1.value}" />
                            <f:attribute name="quantity2" value="#{quantity2.value}" />
                            <f:attribute name="quantity3" value="#{quantity3.value}" />
                        </p:inputText>
                        <h:message styleClass="errorMsg" for= "quantity4" />

                    </h:panelGrid>
                    <br />
                </p:panel>
                <p:commandButton action="#{salesInquiryEntityController.create}" value="Create Inquiry" ajax="false"/> &nbsp;
                <p:commandButton action="#{salesInquiryEntityController.prepareList}" value="Cancel" immediate="true"  ajax="false"/>&nbsp;
                <p:commandButton action="#{salesInquiryEntityController.reset}" value="Reset" immediate="true"  ajax="false"/>
                <p:dialog header="Sales Leads" widgetVar="salesLead" showEffect="fade" hideEffect="fade" position="top" height="500" width="800">  
                    <p:dataTable value="#{salesLeadEntityController.items}" 
                                 var="item" style="table-layout:fixed"
                                 paginator="true" rows="10"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="5,10,15"
                                 selection="#{salesInquiryEntityController.selectedSalesLead}" selectionMode="single"
                                 rowSelectListener="#{salesInquiryEntityController.salesLeadSelect}">
                        <p:column filterBy="#{item.id}">
                            <f:facet name="header">
                                <h:outputText value="Id"/>
                            </f:facet>
                            <h:outputText value="#{item.id}"/>
                        </p:column>                      
                        <p:column filterBy="#{item.firstName}"
                                  filterMatchMode="contains">
                            <f:facet name="header">
                                <h:outputText value="First Name"/>
                            </f:facet>
                            <h:outputText value="#{item.firstName}"/>
                        </p:column>
                        <p:column filterBy="#{item.lastName}"
                                  filterMatchMode="contains">
                            <f:facet name="header">
                                <h:outputText value="Last Name"/>
                            </f:facet>
                            <h:outputText value="#{item.lastName}"/>
                        </p:column>
                        <p:column filterBy="#{item.contact.email}"
                                  filterMatchMode="contains">
                            <f:facet name="header">
                                <h:outputText value="Email"/>
                            </f:facet>
                            <h:outputText value="#{item.contact.email}"/>
                        </p:column>
                        <p:column filterBy="#{item.companyName}"
                                  filterMatchMode="contains">
                            <f:facet name="header">
                                <h:outputText value="Company"/>
                            </f:facet>
                            <h:outputText value="#{item.companyName}"/>
                        </p:column>
                        <p:column filterBy="#{item.customerType}">
                            <f:facet name="header">
                                <h:outputText value="Type"/>
                            </f:facet>
                            <h:outputText value="#{item.customerType}"/>
                        </p:column>
                    </p:dataTable>
                </p:dialog> 
                <p:dialog header="Customers" widgetVar="customer" showEffect="fade" hideEffect="fade" position="top" height="500" width="800">  
                    <p:dataTable value="#{customerEntityController.items}" 
                                 var="item" style="table-layout:fixed"
                                 paginator="true" rows="10"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="5,10,15"
                                 selection="#{salesInquiryEntityController.selectedCustomer}" selectionMode="single"
                                 rowSelectListener="#{salesInquiryEntityController.customerSelect}">
                        <p:column filterBy="#{item.id}">
                            <f:facet name="header">
                                <h:outputText value="Id"/>
                            </f:facet>
                            <h:outputText value="#{item.firstName}"/>
                        </p:column>                      
                        <p:column filterBy="#{item.firstName}"
                                  filterMatchMode="contains">
                            <f:facet name="header">
                                <h:outputText value="First Name"/>
                            </f:facet>
                            <h:outputText value="#{item.firstName}"/>
                        </p:column>
                        <p:column filterBy="#{item.lastName}"
                                  filterMatchMode="contains">
                            <f:facet name="header">
                                <h:outputText value="Last Name"/>
                            </f:facet>
                            <h:outputText value="#{item.lastName}"/>
                        </p:column>
                        <p:column filterBy="#{item.contact.email}"
                                  filterMatchMode="contains">
                            <f:facet name="header">
                                <h:outputText value="Email"/>
                            </f:facet>
                            <h:outputText value="#{item.contact.email}"/>
                        </p:column>
                        <p:column filterBy="#{item.companyName}"
                                  filterMatchMode="contains">
                            <f:facet name="header">
                                <h:outputText value="Company"/>
                            </f:facet>
                            <h:outputText value="#{item.companyName}"/>
                        </p:column>
                        <p:column filterBy="#{item.customerType}">
                            <f:facet name="header">
                                <h:outputText value="Type"/>
                            </f:facet>
                            <h:outputText value="#{item.customerType}"/>
                        </p:column>
                    </p:dataTable>
                </p:dialog> 
            </h:form>
        </ui:define>
    </ui:composition>
</html>
